import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getDwCoordinateData } from '@gis/lib/api';

const typeCodeEnum = {
  zz_01_01: 'zhzf', //综合执法
  zz_01_03: 'zzdy', //综治服务队
  zz_01_04: 'xfy', //消防员
  zz_01_07: 'wgy', //网格员
  // qt: 'dwqt',
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type_code] || 'dwqt'; //很多种类型，没有的使用’其他‘
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick() {
    // dialog({
    //   content: () => import('@/views/grid-team/components/event-list/people-detail.vue'),
    //   contentProps: {
    //     detail: this.data,
    //   },
    //   dialogProps: {
    //     title: '人员详情',
    //     footer: null,
    //   },
    // });
  }
}

export default class Dw extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      dType: 'dw',
      area_code: area_code,
    };
    const data = await handleCommonRes(getDwCoordinateData, params);
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
